<template>
  <div class="scan-page">
    <div class="header">
      <h1>扫码点餐</h1>
    </div>
    
    <div class="scan-area">
      <div class="scan-box">
        <div class="scan-line"></div>
      </div>
      <p>请将二维码放入框内</p>
    </div>
    
    <div class="manual-input">
      <input 
        v-model="tableNumber" 
        placeholder="手动输入桌号" 
        class="table-input"
      />
      <button @click="enterTable" class="enter-btn">进入点餐</button>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useOrderStore } from '../store/orderStore'

export default {
  name: 'ScanPage',
  setup() {
    const router = useRouter()
    const orderStore = useOrderStore()
    const tableNumber = ref('')
    
    // 检查URL参数中是否有桌号
    const urlParams = new URLSearchParams(window.location.search)
    const tableFromUrl = urlParams.get('table')
    
    if (tableFromUrl) {
      orderStore.setTableNumber(tableFromUrl)
      router.push('/people')
    }
    
    const enterTable = () => {
      orderStore.setTableNumber(tableNumber.value)
      router.push('/people')
    }
    
    return {
      tableNumber,
      enterTable
    }
  }
}
</script>

<style scoped>
.scan-page {
  padding: 20px;
  text-align: center;
}

.header h1 {
  color: #333;
  margin-bottom: 30px;
}

.scan-area {
  margin: 30px 0;
}

.scan-box {
  width: 200px;
  height: 200px;
  border: 2px solid #42b983;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.scan-line {
  position: absolute;
  width: 100%;
  height: 2px;
  background-color: #42b983;
  animation: scan 2s infinite linear;
}

@keyframes scan {
  0% {
    top: 0;
  }
  100% {
    top: 100%;
  }
}

.scan-area p {
  margin-top: 20px;
  color: #666;
}

.manual-input {
  margin-top: 40px;
}

.table-input {
  width: 200px;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 20px;
}

.enter-btn {
  background-color: #42b983;
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
}

.enter-btn:hover {
  background-color: #359c6d;
}
</style>